# -*- encoding: utf-8 -*-

import time
from lib.cache.redis_cache import redis_instance
from script import bsc


"""TODO
    - 采集入口
"""

def bsc_scan():
    """
        如果想从头开始采集 (重新加载已完成的结果到bloom), 那么请删除redis 中的key [init_bloom key]
        否则, 默认实现增采集
    """
    # 如果有任务在运行就不执行
    status = redis_instance.hget('process_running', 'bsc')
    if status == 'running':
        return

    # 清理环境
    redis_instance.delete('Interrupt_status')
    redis_instance.delete('currentBatch_execute_status')
    # 开始计时
    start_time = time.perf_counter()
    # 设置采集状态 running
    redis_instance.hset('process_running', 'bsc', 'running')
    # 开始采集
    bsc.run()
    # 结束计时
    end_time = time.perf_counter()
    # 计算耗时
    elapsed_time = end_time - start_time
    print(f'Elapsed time: {elapsed_time:.10f} seconds')

    # 清除采集状态
    redis_instance.hdel('process_running', 'bsc')



if __name__ == '__main__':
    bsc_scan()